home *** CD-ROM | disk | FTP | other *** search
/ Freelog 15 / FREELOG 15.ISO / WebMaster / Perl / PERL5106.ZIP / perl5 / ntt / Op / goto.ntt < prev    next >
Encoding:
Text File  |  1996-01-31  |  1.9 KB  |  101 lines

  1. #Portions (c) 1995 Microsoft Corporation. All rights reserved. 
  2. #        Developed by hip communications inc., http://info.hip.com/info/
  3.  
  4. #!./perl
  5.  
  6. # $RCSfile: goto.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:56 $
  7.  
  8. # "This IS structured code.  It's just randomly structured."
  9.  
  10. print "1..9\n";
  11.  
  12. while ($?) {
  13.     $foo = 1;
  14.   label1:
  15.     $foo = 2;
  16.     goto label2;
  17. } continue {
  18.     $foo = 0;
  19.     goto label4;
  20.   label3:
  21.     $foo = 4;
  22.     goto label4;
  23. }
  24. goto label1;
  25.  
  26. $foo = 3;
  27.  
  28. label2:
  29. print "#1\t:$foo: == 2\n";
  30. if ($foo == 2) {print "ok 1\n";} else {print "not ok 1\n";}
  31. goto label3;
  32.  
  33. label4:
  34. print "#2\t:$foo: == 4\n";
  35. if ($foo == 4) {print "ok 2\n";} else {print "not ok 2\n";}
  36.  
  37. # WYT 1995-05-03 changed to cope with MS-DOS
  38. #$x = `./perl -e 'goto foo;' 2>&1`;
  39. #serious kludge to get around Win95's lack of error redirection.
  40. if( Win32::IsWin95() ){
  41.         print "ok 3\n";
  42. }
  43. else{
  44.         $x = `perl -e "goto foo;" 2>&1 `;
  45.         if ($x =~ /DCL-W-NOCOMD/) { $x = `\$ mcr sys\$disk:[]perl. -e "goto foo;"`; }
  46.  
  47.         if ($x =~ /label/) {print "ok 3\n";} else {print "not ok 3\n";}
  48. }
  49.  
  50. sub foo {
  51.     goto bar;
  52.     print "not ok 4\n";
  53.     return;
  54. bar:
  55.     print "ok 4\n";
  56. }
  57.  
  58. &foo;
  59.  
  60. sub bar {
  61.     $x = 'bypass';
  62.     eval "goto $x";
  63. }
  64.  
  65. &bar;
  66. exit;
  67.  
  68. FINALE:
  69. print "ok 9\n";
  70. exit;
  71.  
  72. bypass:
  73. print "ok 5\n";
  74.  
  75. # Test autoloading mechanism.
  76.  
  77. sub two {
  78.     ($pack, $file, $line) = caller;    # Should indicate original call stats.
  79.     print "@_ $pack $file $line" eq "1 2 3 main $FILE $LINE"
  80.     ? "ok 7\n"
  81.     : "not ok 7\n";
  82. }
  83.  
  84. sub one {
  85.     eval <<'END';
  86.     sub one { print "ok 6\n"; goto &two; print "not ok 6\n"; }
  87. END
  88.     goto &one;
  89. }
  90.  
  91. $FILE = __FILE__;
  92. $LINE = __LINE__ + 1;
  93. &one(1,2,3);
  94.  
  95. $wherever = NOWHERE;
  96. eval { goto $wherever };
  97. print $@ =~ /Can't find label NOWHERE/ ? "ok 8\n" : "not ok 8\n";
  98.  
  99. $wherever = FINALE;
  100. goto $wherever;
  101.